<?php


namespace App\Http\Controllers\admin\api;


use App\Http\Controllers\admin\service\ManualService;
use App\Http\Controllers\admin\validate\Manual;
use App\Http\Controllers\utils\ToolUtil;
use App\Http\Controllers\utils\UploadUtil;
use Illuminate\Http\Request;

class ManualApi
{
    public function uploadPdf(Request $request){
        $param = $request->all();
        $data = Manual::uploadPdf($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        $path = 'homework/pdf/p'.'-'.time().'-'.mt_rand(100,999).'.pdf';
        $oss_url = UploadUtil::uploadAliOss($path,$param['file']);
        return ToolUtil::returnJson(200,'成功',$oss_url);
    }

    public function addManual(Request $request){
        $param = $request->all();
        $data = Manual::addManual($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return ManualService::addManual($param);
    }

    public function queryManual(Request $request){
        $param = $request->all();
        $data = Manual::queryManual($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return ManualService::queryManual($param);
    }

    public function deleteManual(Request $request){
        $param = $request->all();
        $data = Manual::deleteManual($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return ManualService::deleteManual($param);
    }

    public function downloadManual(Request $request){
        $param = $request->all();
        $data = Manual::downloadManual($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return ManualService::downloadManual($param);
    }
}